using Mapster;
using SmartCommunity.Models;
using System.ComponentModel.DataAnnotations;

namespace SmartCommunity.Services.Workorder
{
    #region DTO属性映射
    /// <summary>
    /// 属性映射 WorkOrderDtoRegister
    /// </summary>
    public class WorkOrderDtoRegister : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            // config.ForType<WorkOrderEntity, WorkOrderDto>().Map(d => d.DeptName, s => s.Dept.DeptName, s => s.Dept != null);
        }
    }
    #endregion

    #region 数据传输对象 WorkOrderDto
    /// <summary>
    /// 数据传输对象：工单池
    /// </summary>
    public class WorkOrderDto : BaseDto
    {
        /// <summary>
        /// 工单ID
        /// </summary>
        public Guid OrderId { get; set; }

        /// <summary>
        /// 工单编号
        /// </summary>
        [StringLength(45, ErrorMessage = "工单编号 长度不能超过 45.")]
        public string OrderNo { get; set; } = string.Empty;

        /// <summary>
        /// 工单类型
        /// </summary>
        public int OrderType { get; set; }

        /// <summary>
        /// 工单描述
        /// </summary>
        [Required(ErrorMessage = "工单描述不能为空")]
        [StringLength(4000, ErrorMessage = "工单描述 长度不能超过 4000.")]
        public string Description { get; set; } = string.Empty;

        /// <summary>
        /// 工单状态
        /// </summary>
        public int OrderStatus { get; set; }

        /// <summary>
        /// 提交人
        /// </summary>
        [StringLength(45, ErrorMessage = "提交人 长度不能超过 45.")]
        public string? SubmitPerson { get; set; }

        /// <summary>
        /// 提交人电话
        /// </summary>
        [StringLength(45, ErrorMessage = "提交人电话 长度不能超过 45.")]
        public string? SubmitTel { get; set; }

        /// <summary>
        /// 小区ID
        /// </summary>
        public Guid? SubmitAreaId { get; set; }

        /// <summary>
        /// 提交人房号
        /// </summary>
        public Guid? SubmitRoomId { get; set; }

        /// <summary>
        /// 提交人地址
        /// </summary>
        [StringLength(45, ErrorMessage = "提交人地址 长度不能超过 45.")]
        public string? SubmitAddr { get; set; }

        /// <summary>
        /// 提交时间
        /// </summary>
        public DateTime? SubmitTime { get; set; }

        /// <summary>
        /// 评价星级
        /// </summary>
        public int? RateStars { get; set; }

        /// <summary>
        /// 评价内容
        /// </summary>
        [StringLength(2000, ErrorMessage = "评价内容 长度不能超过 2000.")]
        public string? RateContent { get; set; }

        /// <summary>
        /// 工单处理人账号
        /// </summary>
        public int? HandleUser { get; set; }

        /// <summary>
        /// 工单处理人姓名
        /// </summary>
        [StringLength(45, ErrorMessage = "工单处理人姓名 长度不能超过 45.")]
        public string? HandleUserName { get; set; }

        /// <summary>
        /// 处理结果
        /// </summary>
        [StringLength(2000, ErrorMessage = "处理结果 长度不能超过 2000.")]
        public string? HandleResult { get; set; }

        public string? OrderTypeName { get; set; }
        public string? OrderStatusName { get; set; }


    }
    #endregion

    #region 数据查询对象
    /// <summary>
    /// 查询模型：工单池
    /// </summary>
    public class WorkOrderQuery : AbstractQuery<WorkOrderEntity>
    {
        /// <summary>
        /// 主键ID多选查询
        /// </summary>
        public IEnumerable<Guid> Ids { get; set; } = [];

        /// <summary>
        /// 根据查询条件添加查询表达式
        /// </summary>
        protected override void MergeQueryExpression()
        {
            AddExpression(Ids.Any(), e => Ids.Contains(e.OrderId));
            // AddStringExpression(RoleCode, r => r.RoleCode == RoleCode);
            // AddSearchExpression(s => o => o.RoleCode.Contains(s) || o.RoleName.Contains(s));
            // AddDateExpression(start => e => e.CreatedTime >= start, end => e => e.CreatedTime <= end);
        }
    }
    #endregion
}
